﻿using UnityEngine;
#if  UNITY_IOS&&!DEVELOP
using System.Runtime.InteropServices;
#endif
namespace QQSDK
{
   
    public class FireBaseManager
    {
        private const string PACKAGE_NAME_FireBase = "com.qq.firebase.FireBaseManager";

#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK

        [DllImport("__Internal")]
        private static extern void logFirebaseEvent(string eventName, string par);

        [DllImport("__Internal")]
        private static extern void setFirebaseUserProperty(string eventName, string eventValue);
                
#elif UNITY_ANDROID
        public static AndroidJavaObject AJO;

#endif

        public static void Set()
        {
            
            //第三方 -- Firebase
            SDKFunc.Log("set Firebase");
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
#elif UNITY_ANDROID
            try
            {
                if (ToolsManager.CheckClass(PACKAGE_NAME_FireBase))
                {
                    AndroidJavaClass tmp = new AndroidJavaClass(PACKAGE_NAME_FireBase);
                    if (tmp != null)
                    {
                        AJO = tmp.CallStatic<AndroidJavaObject>("instance");
                    }
                }
            }
            catch
            {
                SDKFunc.Log("set Firebase error");
            }
#elif UNITY_WEBGL

#else

#endif
        }



        public static void LogFirebaseEvent(string eventName, string par = "")
        {
            SDKFunc.Log("LogFirebaseEvent,eventName=" + eventName+ ",par=" + par);
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
            logFirebaseEvent(eventName, par);
#elif UNITY_ANDROID
            if (AJO != null)
                AJO.Call("logFirebaseEvent", eventName, par);
#endif
        }

        public static void SetFirebaseUserProperty(string eventName, string eventValue)
        {
            SDKFunc.Log("SetFirebaseUserProperty,eventName=" + eventName + ",eventValue=" + eventValue);
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
            setFirebaseUserProperty(eventName, eventValue);
#elif UNITY_ANDROID
            if (AJO != null)
                AJO.Call("setFirebaseUserProperty", eventName, eventValue);
#endif
        }

        public static void LogFirebaseRevenueEvent(double revenue, string networkName, string adType)
        {
            SDKFunc.Log("LogFirebaseRevenueEvent,revenue=" + revenue + ",networkName=" + networkName + ",adType=" + adType);
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK

#elif UNITY_ANDROID
            if (AJO != null)
                AJO.Call("logFirebaseRevenueEvent", revenue ,networkName ,adType);
#endif
        }


    }
}